package com.zxh.zhenxihuan.service.impl;

import com.zxh.zhenxihuan.entity.Goods;
import com.zxh.zhenxihuan.entity.z.Address;
import com.zxh.zhenxihuan.mapper.AddressMapper;
import com.zxh.zhenxihuan.service.AddressService;
import com.zxh.zhenxihuan.util.Page;
import io.swagger.models.auth.In;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 */
@Service("addressService")
public class AddressServiceImpl implements AddressService {

    @Resource
    private AddressMapper addressMapper;

    @Override
    @Transactional(propagation = Propagation.REQUIRED,timeout = -1,rollbackFor = Exception.class)
    public Page<Address> page(Integer num, Integer count,String uid) {
        Integer pageNum=1;
        try{
            pageNum=Integer.valueOf(num) ;
        }catch(Exception e){
            e.printStackTrace();
        }
        Integer pageCount=10;
        try{
            pageCount=Integer.valueOf(count);
        }catch(Exception e){
            e.printStackTrace();
        }

        Page<Address> page=new Page<>();
        page.init(pageNum,pageCount,getSum(uid));
        page.setList(getAddress(page.getRowNum(),pageCount,uid));
        return page;
    }


    @Override
    public Integer getSum(String uid) {
        Integer num=addressMapper.getSum(uid);
        return num;
    }

    @Override
    public List<Address> getAddress(Integer start, Integer end,String uid) {
        List<Address> list = addressMapper.getAddress(start, end,uid);
        for (Address address : list) {
            System.out.println(address);
        }
        return list;
    }

    @Override
    public Integer del(Integer id) {
        Integer num=addressMapper.del(id);
        return num;
    }
}
